package com.kingsoft.dc.khaos.module.spark.util;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.security.UserGroupInformation;
import org.elasticsearch.hadoop.cfg.ConfigurationOptions;

import java.io.File;
import java.io.IOException;

/**
 * Create by wuxiang on 2022/5/10
 */
public class Krb5Utils {
    public static UserGroupInformation doLogin(String principal, String keytab, Configuration conf) throws IOException {
        UserGroupInformation.setConfiguration(conf);
        UserGroupInformation.loginUserFromKeytab(principal, keytab);
        return UserGroupInformation.getLoginUser();
    }

    public static Configuration setHbaseConf(Configuration conf) {
        conf.set("hadoop.security.authentication", "kerberos");
        conf.set("hbase.security.authentication", "kerberos");
        conf.setInt("hbase.client.retries.number", 2);
        conf.setInt("zookeeper.recovery.retry", 3);
        conf.set("hbase.regionserver.kerberos.pricipal", "hbase/_HOST@HADOOP.COM");
        return conf;
    }

}
